package com.wcgksoft.controller.greedLand;

import com.wcgksoft.common.util.Layui;
import com.wcgksoft.entity.GreedLand.GreedLand;
import com.wcgksoft.entity.system.EnterpriseProject;
import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.service.GreedLand.GreedlandAdministratorService;
import com.wcgksoft.service.GreedLand.GreedlandService;
import org.apache.shiro.SecurityUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 绿地明细
 *
 * @return
 */
@Controller
@RequestMapping(value = "greedLanddetail")
public class GreedLandDetailController {
    @Autowired
    private GreedlandService greedlandService;
    @Autowired
    private GreedlandAdministratorService greedlandAdministratorService;
    /**
     *专业
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "list")
    public Layui list(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "limit", required = false) Integer limit
           ) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GreedLand.class);
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute("om_user");
        EnterpriseProject enterpriseProject = (EnterpriseProject) SecurityUtils.getSubject().getSession().getAttribute("area");
        criteria.add(Restrictions.eq("departid", sysUser.getProId()+""));
        criteria.add(Restrictions.eq("areaid", enterpriseProject.getId()+""));
        criteria.add(Restrictions.eq("dataClassify","0" ));
        criteria.add(Restrictions.eq("state",0 ));
        List<GreedLand> list = greedlandService.findByConditions(criteria, page, limit);
        return Layui.data(0, "查询成功", greedlandService.getTotalCount(), list);
    }
    /**
     *群植
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "list1")
    public Layui list1(
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "limit", required = false) Integer limit
    ) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GreedLand.class);
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getSession().getAttribute("om_user");
        EnterpriseProject enterpriseProject = (EnterpriseProject) SecurityUtils.getSubject().getSession().getAttribute("area");
        criteria.add(Restrictions.eq("departid", sysUser.getProId()+""));
        criteria.add(Restrictions.eq("areaid", enterpriseProject.getId()+""));
        criteria.add(Restrictions.eq("dataClassify","1"));
        criteria.add(Restrictions.eq("state",0 ));
        List<GreedLand> list = greedlandService.findByConditions(criteria, page, limit);
        return Layui.data(0, "查询成功", greedlandService.getTotalCount(), list);
    }


}
